﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title></title>
	<link href="js-console.css" rel="stylesheet" />
	<!-- 1. Write a function that returns the last digit of given 
			integer as an English word. Examples: 512 -> "two", 
			1024 -> "four", 12309 -> "nine" -->
</head>
<body>
	<div id="js-console"></div>
	<script src="js-console.js"></script>
	<script>
		function digitToString(number) {
			var result = "";

			switch (number) {
				case 0:
					result = "zero";
					break;
				case 1:
					result = "one";
					break;
				case 2:
					result = "two";
					break;
				case 3:
					result = "three";
					break;
				case 4:
					result = "four";
					break;
				case 5:
					result = "five";
					break;
				case 6:
					result = "six";
					break;
				case 7:
					result = "seven";
					break;
				case 8:
					result = "eight";
					break;
				case 9:
					result = "nine";
					break;
			}

			return result;
		}

		var number = parseInt(prompt("Enter number"));

		if (!isNaN(number)) {
			var lastDigit = number % 10;
			jsConsole.writeLine("The last digit is: " + digitToString(lastDigit));
		}
		else {
			jsConsole.writeLine("Wrong input.");
		}
	</script>
</body>
</html>
